package com.symaster.common.animation;

import com.symaster.common.animation.nest4jv2.data.NestPath;
import com.symaster.common.animation.nest4jv2.data.Segment;
import com.symaster.common.geom.entity.Node;
import com.symaster.common.geom.entity.Polygon;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.symaster.common.util.CommonUtil.getId;

/**
 * @author yinmiao
 * @version 2023-03-24 18:53
 */
public class Nest4J {

    /**
     * 使用1或者2
     */
    public static final int NEST_VERSION = 2;

    public static <T extends Node> List<T> layout(List<T> nodes, double width) {

        for (T node : nodes) {
            if (node.getId() == null) {
                node.setId(getId());
            }
        }

        Map<Integer, T> collect = nodes.stream().collect(Collectors.toMap(Node::getId, e -> e));

        if (2 == NEST_VERSION) {

            List<NestPath> collect1 = nodes.stream().map(e -> {
                Polygon polygon = e.getPolygon();
                double[] xpoints = polygon.getXpoints();
                double[] ypoints = polygon.getYpoints();

                NestPath nestPath = new NestPath();
                for (int i = 0; i < xpoints.length; i++) {
                    nestPath.add(new Segment(xpoints[i], ypoints[i]));
                }
                nestPath.bid = e.getId();
                return nestPath;
            }).collect(Collectors.toList());

            NestPath nestPath = new NestPath();

            return null;
        } else {
            return null;
        }
    }

}
